Analysis of Magnetic Field Measurements for Indoor Positioning

Infrastructure-free magnetic fields are ubiquitous and have attracted tremendous interest in magnetic field-based indoor positioning. However, magnetic field-based indoor positioning applications face challenges such as low discernibility, heterogeneous devices, and interference from ferromagnetic materials. This paper first analyzes the statistical characteristics of magnetic field (MF) measurements from heterogeneous smartphones. It demonstrates that, in the absence of disturbances, the MF measurements in indoor environments follow a Gaussian distribution with temporal stability and spatial discernibility. It shows the fluctuations in magnetic field intensity caused by the rotation of a smartphone around the Z-axis. Secondly, it suggests that the RLOWESS method can be used to eliminate magnetic field anomalies, using magnetometer calibration to ensure consistent MF measurements in heterogeneous smartphones. Thirdly, it tests the magnetic field positioning performance of homogeneous and heterogeneous devices using different machine learning methods. Finally, it summarizes the feasibility/limitations of using only MF measurement for indoor positioning.


Introduction
The global indoor positioning market size is expected to grow at a Compound Annual Growth Rate of 22.5%, from USD 6.1 billion in 2020 to USD 17 billion by 2025 [1]. Advanced indoor positioning technologies that can obtain accurate location information and provide consumers with reliable location-based services and information are promising and attractive research areas. Location-based services include indoor navigation and tracking, marketing (shopping advertisements, proximity-based coupon sharing), entertainment (location-based social networking, location-based gaming), location-based information retrieval (e.g., pavilion tours, underground real-time information), and emergency and safety applications (e.g., emergency calls, automotive assistance) [2,3].
While GNSS is unable to meet indoor positioning requirements due to signal attenuation and obstacles, many alternative technologies and devices are used for indoor positioning, such as Wi-Fi [4], Bluetooth [5,6], ultrasound or sound [7,8], visible light [9,10], and magnetic field [11,12]. Table 1 describes the advantages and disadvantages of these positioning techniques in detail.
Magnetic-based positioning technology has attracted continued interest in academia [13,14] and industry [15,16] due to the popularity of smartphones, tablets, and personal digital agents (PDAs) with embedded magnetometers. As an emerging indoor positioning method, magnetic-based positioning uses the Earth and the local magnetic field • Slow propagation speed (around 340 m/s); • Limited influence of the surroundings and good penetration of walls.
• Multipath effects and attenuation.
• High fingerprint collection effort; • Vulnerable to access point changes; • Fluctuation of Wi-Fi signal; • Radio mismatch problems; • Heterogeneity of Wi-Fi devices; • Noise and multipath distortion.
• Shorter range; • Extra infrastructure requirement; • High cost for users.
• High infrastructure changes on the transmitter side; • The burden on the user; • Complex infrastructure.
Vision (camera) [22] Line of sight condition 0.01∼1 m • High positioning accuracy; unaffected by the external environment; • Strong anti-interference capability.
• Complex algorithms; • High power consumption; • Sensitive to light conditions; • Expensive and lacks wide applications.
Inertial navigation [23] Hundreds of meters 2 m • Low cost; • Easy to deploy.
• Subject to the accuracy of inertial sensors; • Accumulation of drift and deviation errors.
However, magnetic field-based positioning still has many limitations. The magnetic field intensity of the Earth's surface varies smoothly between 23 µT and 62 µT [25]. The magnetic field measurement has only three components, which leads to its low discernibility. Embedded magnetometers of heterogeneous smartphones are produced by different suppliers with different noise tolerances and accuracies, resulting in different MF measurements of heterogeneous smartphones. Seamlessly connecting all heterogeneous smartphone positioning solutions is therefore very challenging [26].
This paper analyzes the challenges and feasibility of magnetic-based positioning through systematic experiments. In conclusion, the main contributions of this paper are as follows: • A magnetic field acquisition system was developed using the Arduino Pro Mini and the LSM9DS1. The RLOWESS smoothing filter was proposed to eliminate the effects of noise, distortion, and outliers in the raw MF measurements. • Static tests, trajectory tests, and rotational tests were designed to investigate the magnetic characteristics of the heterogeneous smartphone. • Calibration tests of heterogeneous smartphones were carried out to demonstrate the potential of smartphone calibration in solving the heterogeneous device problem of MF. • Classification tests of heterogeneous smartphones were performed to show the feasibility of magnetic field positioning.
This paper is organized as follows. In Section 2, we present related works in the literature about MF characteristics. The magnetometer measurement model is introduced in Section 3. In Section 4, we discuss the statistical characteristics of the magnetic field and its temporal stability, compare the similarity of the magnetic field trajectories of heterogeneous smartphones, and present the variation of MF intensity with device orientation for the uncalibrated case. In Section 5, we compare the characteristics of 'calibrated' MF for heterogeneous smartphones. In Section 6, we use different machine learning methods to compare the positioning performance of homogeneous and heterogeneous smartphones. Finally, Section 7 summarizes the paper and highlights the challenges of magnetic field positioning.

Related Work
Many research works exist in the literature relative to indoor positioning and navigation using MF measurement.
MF characteristics have been thoroughly analyzed in works [26][27][28][29][30]. Li et al. [27] conducted experiments where indoor magnetic flow density was measured in different environments. The results show stable magnetic flow density measurements over a 24 h period. The experiments were repeated three months later, and no significant change was detected. It has been observed that the MF intensity of four different smartphone models differs due to the sensors' different sensitivities [28]. This problem can be solved by normalization, but it will reduce the accuracy of positioning. Two smartphones were also placed in the exact location for long-time data collection to demonstrate that the MF intensity is time-stable. However, due to the smartphone battery capacity limitation, the data collection time will not exceed one day. Some anomalies brought about by the change in MF over time cannot be observed. Shu et al. [30] tested MF measurements on heterogeneous smartphones with different attitudes. They showed the uniqueness of local magnetic disturbance, the temporal stability of MF measurements, and the tolerance of MF measurements to moving objects. However, they highlight that heterogeneous devices have different MF measurements in the exact location. As MF measurements are threedimensional and directional, the reference frame of the magnetometer is not easily aligned with the world frame, which leads to the use of only the magnitude of MF measurements in practice and makes it difficult to use three-dimensional MF measurements to improve discernibility. Ashraf et al. [26] provided a comprehensive analysis of the advantages and disadvantages of MF measurement. They highlighted the heterogeneity of smartphones, the height and behavior of users, and the low discernibility of MF measurements. Smartphone-based positioning is often more complex due to complex user behavior, e.g., user height, handheld smartphone position. The work in [29] studied MF intensity and direction distribution features. Using data from accelerometers and gyroscopes to obtain rotation matrices to transform the magnetic field coordinate system will increase the system's complexity. To avoid the coordinate transformation, the work in [14] used the gradient of the MF values between two consecutive steps to avoid calibrating different smartphones. Since the magnetic pattern from heterogeneous smartphones is not the same, the work [31] proposed to use magnetic data from multiple smartphones to make the magnetic pattern. The authors propose an algorithm that identifies outliers in the MF data, removes them, and then normalizes the selected data to calculate the magnetic pattern. The effect of user height on the performance of magnetic-based positioning algorithms with two male and two female users was analyzed in the work [32]. The MF vector measured by the magnetometer is related to the orientation of the sensor and the position and orientation can be identified by an augmented MF vector with a directional variation [33]. As the MF vector can produce many different vectors in different attitudes, it can be trained by a transformed MF vector. The calibrated smartphone and magnetometer were found to have similar magnetic fingerprints [34]. GPS and Wi-Fi, as well as hand-held smartphones, do not significantly affect the measurement results. The peaks and drops of the MF signal can be used to identify certain areas. The effects of different metals and electronic objects on the MF were compared. MF measurements in indoor environments obviously vary more than those in outdoor environments. The quality of the positioning depends on the number of components used. When all three components are used, the performance of MF positioning is good. When using only the magnitude, or the vertical and horizontal components, the positioning performance decreases rapidly.
Indoor mapping is a prerequisite for indoor positioning systems. He et al. [30] use a site survey method based on compliance walks. This traditional map construction requires hiring experts to build indoor maps and update them regularly, which is an expensive and time-consuming method that cannot be applied to large-scale indoor coverage. In recent years, crowdsourcing, SLAM, as well as Gaussian processes have been proposed for constructing magnetic maps [35]. Crowdsourcing is an approach that uses crowd contributions to achieve complex tasks and is well suited for magnetic map construction [36]. For example, the works [37][38][39] used crowdsourcing to merge sensor data from multiple users on different paths to build a magnetic map. PFSurvey [40] uses accelerometer, gyroscope, and magnetometer data to estimate the trajectory of the surveyor and uses SLAM and particle filters to incorporate the floor plans of buildings, allowing for the rapid construction of magnetic field maps. PFSurvey's data collection costs are low, yet it achieves similar accuracy to traditional site survey methods. Combining the physical properties of the magnetic field with a Gaussian process to model the magnetic field components allows for continuous updating of the estimates and the time variation of the magnetic field to build magnetic field maps quickly [41][42][43][44][45] Magnetic field positioning methods can be divided into five categories: magnetic landmark, dynamic time warping, filtering method, SLAM, and neural network method.
Equipment with ferromagnetic materials (e.g., refrigerators, lifts, metal doors, etc.) can cause MF measurements to show prominent variations, and this magnetic disturbance can be used as a magnetic landmark to enhance indoor positioning and mapping [46][47][48], to detect indoor/outdoor environments [49], and to label the semantics of indoor environments [50].
Different walking speeds and sampling rates produce different numbers of magnetic samples within the same spatial coverage. Dynamic time warping (DTW) could align two magnetic field sequences with similar patterns but different amplitudes and times by compressing or stretching the time axis of one (or both) magnetic field sequences. Subbu et al. [51] use DTW to classify magnetic signatures collected from different corridors. By aligning unknown magnetic signatures with known signatures, the technique can obtain a close match between test and specific, temporally distinct magnetic signatures, thus providing correct corridor/location information. Through a similar method, Perez-Navarro et al. [52] showed that magnetic fields are a promising positioning mechanism when only the user's zone needs to be located. Wang et al. [53] used DTW as a distance function to quantify the similarity between two signature vectors with different spatial sampling densities to match magnetic trajectories. The matched magnetic trajectories were used to calibrate the pedestrian dead reckoning (PDR) position, and the authors used online-collected magnetic trajectories to construct backward magnetic trajectories to increase the probability of improving the PDR position. By averaging the direction of travel for all steps between two successive detected turns, the authors reduced fluctuations in the direction of travel caused by user movement, sensor noise, local magnetic anomalies, and other electrical disturbances. In addition, 3DDTW [54], which extends the one-dimensional input signal into a two-dimensional signal, calculates the distance between the MF measurement and the magnetic fingerprinting, thus reducing the mismatch between the magnetic signature. CSMS [55] integrates channel state information (CSI) and magnetic field strength (MFS). Initial positions are first obtained by the M-KNN method. Then, DTW is applied to match the magnetic sequence during the motion for tracking. Finally, the k-nearest neighbor algorithm calculates the weights and narrows down the positioning range for fingerprint matching.
Machine learning methods such as K-NN [56], support vector machines (SVM) [57], naive Bayes [58], decision trees [59], and discriminant analysis [60] are widely used to extract the core features of a signal. The advantage of the machine learning approach is its ability to learn helpful information from input data with known or unknown statistics [61]. Galván-Tejada et al. [62] proposed a "signature" obtained by walking randomly around the room, using the spectrum, skewness, kurtosis, and variance of the magnetic signal as features. A genetic algorithm (GA) was used as the feature selection algorithm for data dimensionality reduction. However, the authors used only one-dimensional MF intensity and did not consider calibrating MF measurements of heterogeneous smartphones. Chuang et al. [11] designed a system with four magnetometers to evaluate the MF strength in each direction and used the nearest neighbor method to classify MF measurements with 12 components. The MF measurements of two different floors could be distinguished. The effects of smartphones, watches, laptops, elevators, and workbenches on the intensity of the MF were analyzed. Their system used chest-hung magnetometers instead of smartphones, which, in reality, do not have four magnetometers to measure the magnetic fingerprints in all directions.
Filter-based methods (e.g., Hidden Markov Model (HMM), Kalman filter, particle filter) have many indoor magnetic field positioning applications. Filter-based methods can fuse data from multiple sensors to provide higher positioning accuracy. For example, the work of Basmag [63] used a Backward Sequence Matching Algorithm (BSMA) to optimize the HMM and improve the low discriminability of the magnetic signal with the help of PDR. An HMM-based unsupervised learning algorithm was proposed in work [64] to compare the similarity of magnetic fingerprints with a lightweight algorithm. The extended Kalman filter could reduce the cumulative error of inertial sensors and improve orientation and positioning accuracy [65]. A reliability-augmented particle filter was mentioned in [66]; they used a dynamic step estimation algorithm and a heuristic particle resampling algorithm to reduce the error of motion estimation and improve the robustness of the particle filter. The work [67] employed the extended Kalman filter and particle filter to fuse information obtained from pedestrian dead reckoning and magnetic fingerprints, showing higher positioning performance than using the particle filter alone.
SLAM-based magnetic field positioning was recently presented in the work [47,68]. MagSLAM [68] used MF and human stride measurements without using a priori maps. Unique patterns in a smartphone's accelerometer when climbing stairs, unusual magnetic disturbance at specific locations, and unique Wi-Fi access can serve as unique signatures in indoor environments. SemanticSLAM [47] adopted these unique signatures as landmarks and combined them with the pedestrian dead reckoning in the SLAM framework to reduce localization errors and convergence times. This approach is proven to be calibrationfree. SLAM based on magnetic field measurements has two main challenges. Firstly, the construction of maps for large-scale indoor environments is challenging. Secondly, the continuous data exchange between the map and the positioning algorithm is energyintensive [69].
Artificial neural networks (ANNs) are often used for classification and prediction, and researchers have recently applied ANNs to MF positioning. The MF maps are used to train the NN in the offline phase. The real-time MF measurements are fed into the trained NN to estimate its position in the online phase. The two main types of ANN-based magnetic field positioning are convolutional neural networks (CNN) and recurrent neural networks (RNN). The work in [32,[70][71][72][73] uses CNNs to convert MF fingerprints into "image patterns" for classification, and the work in [74][75][76][77][78] uses RNNs to predict MF measurements as time series.
There are several limitations to the above studies. Firstly, they directly used the magnetic field data to predict the user's current location, without pre-processing the magnetic field in conjunction with the magnetometer measurement model. Secondly, due to the battery capacity limitations of smartphones, magnetic field measurements cannot be collected continuously for long periods. Thirdly, although several research works have given solutions for heterogeneous smartphones, it is not clear whether the calibration parameters will change over time and whether they need to be calibrated at every point in space. Fourthly, uncalibrated magnetic field measurement varies with the orientation of the device. Magnetic field measurements in a specific direction can only be matched to the magnetic field fingerprint in that specific direction. Finally, the above studies used homogeneous smartphones and did not use fingerprint databases from heterogeneous smartphones when testing the positioning algorithms. This study aims to provide an exhaustive analysis of magnetic field-based indoor positioning and experimentally explore the feasibility and challenges of magnetic field-based indoor positioning.

Magnetometer Measurement Model
The magnetometer measures the MF intensity along the x, y, and z axis of the sensor. Magnetometers are essential auxiliary sensors for attitude estimation in low-cost, high-performance inertial navigation systems. The fusion of magnetometer and inertial sensor can obtain accurate 3D attitude estimation [79,80]. The accuracy of 3D attitude estimation is closely related to the calibration of sensor measurements [81]. Magnetometers are more sensitive to environmental changes than inertial sensors and require frequent recalibration [82]. Generally, there are two main types of error sources in magnetometers. One type is the non-orthogonality, scale factor, and bias caused by technical limitations in the sensor's manufacturing, installation, and materials. The other is the hard and soft iron effect caused by ferromagnets around the sensor [83].
Complete three-axis magnetometer measurements can be expressed as: In Equation (1), m n ∈ R 3×1 represents the Earth's geomagnetic field vector in navigation frame n aligned with the Earth's gravity. m b ∈ R 3×1 represents the measured magnetic vector in the sensor body frame b. R bn ∈ R 3×3 represents the rotation matrix that transforms the magnetic vector from the navigation frame n to the sensor body frame b. The scale factor S ∈ R 3×3 represents the difference in sensitivity of the three axes. The matrix M ∈ R 3×3 indicates the misalignment errors of sensors. The vector b so ∈ R 3×1 represents the bias in sensors. The matrix A si ∈ R 3×3 represents the soft iron distortion. The vector b hi ∈ R 3×3 represents the hard iron bias. ε represents an i.i.d Gaussian noise from N 0, σ 2 ε I . Each of these error terms will be discussed in detail below. Suppose that ε x ∈ R 3×1 , ε y ∈ R 3×1 , and ε z ∈ R 3×1 represent the skew error of sensors' x, y, and z axis in the sensor frame, respectively. M can be modeled as: The scale factor errors are modeled as where s x , s y , and s z denote the scale factor of the sensors' x, y, and z axis, respectively.
The sensor bias is modeled as where so x , so y , and so z denote the sensor bias of the sensors' x, y, and z axis.
In an outdoor environment, the local geomagnetic field is equal to the local Earth's MF. Its horizontal component points to the magnetic north pole of the Earth [84]. In the absence of any magnetic interference, by rotating the magnetometer in all possible directions, the MF measurements are located on a sphere with a radius equal to the MF intensity.
However, metals such as nickel and iron could cause the soft iron effect, which distorts the sphere into an ellipsoid, as shown on the plot of Figure 1a. This distortion is denoted by A si ∈ R 3×3 . The hard iron effect is denoted b hi ∈ R 3×3 and is produced by materials that exhibit a constant additional field to the Earth's MF, shown in Figure 1b. This distortion shifts the origin of the ideal magnetic measurement sphere. Hence, with the hard iron and soft iron effect, the magnetometer measurement model can be written as: It is not necessary to identify all the components of Equation (1). Expanding Equation (1), the scale factor, misalignment, and soft iron distortion can be combined into a distortion matrix A ∈ R 3×3 , and the hard iron effect and sensor bias can be formed into an offset vector b ∈ R 3×1 .
Hence, the magnetometer measurement model can be expressed as: In the following section, we will use the magnetometer measurement model to analyze the MF signal, the statistical characteristics of a heterogeneous device, and the influence of the distortion matrix A and the offset b.

Analysis of the MF Characterisctics
In this section, we analyze the MF measurement characteristics of a heterogeneous smartphone through static, trajectory, and rotation tests. Several heterogeneous smartphones were used in the experiments. Table 2 describes the system version, the sensor vendors, the model, and the characteristics of the magnetometer. Android sensor information is available through the Android API, while iPhone sensor information is not available directly from the iOS API but only through publicly available information. The Huawei P9, Redmi Note 10 Pro, and Samsung S9 all use different magnetometer models from AKM (Asahi Kasei Microdevices), and Bluebird uses magnetometers from MEMSIC Inc. As the iPhone has no interface to obtain detailed information about the sensors [85,86], we could not find information on the iPhone sensor's manufacturer, model, range, and resolution. The heterogeneity of smartphones is caused by the different characteristics of magnetometers, making it very difficult to design a positioning system that can seamlessly connect various smartphones [26,32].
This paper investigates the MF measurements of the Android and iOS devices. All smartphones used MATLAB Mobile software to collect MF measurements to prevent the effects of software differences. In Section 4.1, we study the statistical characteristics and Gaussianity of heterogeneous smartphones. In Section 4.2, we compare the MF trajectories of heterogeneous smartphones, and in Section 4.3, we test the MF characteristics of smartphones when they are rotated. In Section 4.4, we design a magnetic field acquisition device using the Arduino Pro Mini and the LSM9DS1 and analyze the original magnetometer's statistical characteristics.

Statistical Tests with Heterogeneous Smartphones
Ferromagnetic materials in modern buildings, such as steel casing, electrical equipment, vending machines, etc., can cause local magnetic disturbance. Magnetic-based indoor positioning requires that the magnetic field measurement remain stable over a relatively long time. It is important to design a positioning method that can seamlessly integrate with the MF measurements of various smartphones [26]. Hence, we first investigate the indoor magnetic field's temporal stability, Gaussianity, and heterogeneity.
Three heterogeneous smartphones (iPhone Xs Max, Huawei P9, Bluebird) were used to investigate the MF's statistical characteristics with heterogeneous smartphones.
The three smartphones were placed at a specific point on a wooden table without ferromagnetic material, and the orientation was kept consistent, with a sampling frequency of 100 Hz during a period of 35 min. We found that although the experiment was set at a sampling frequency of 100 Hz, the heterogeneous smartphones could not always reach the set frequency. The iPhone Xs Max sampled at 100 Hz, the Huawei P9 at 103 Hz, and the Bluebird could only reach 80 Hz. The sampling frequency that we can achieve is related to the processor performance of the smartphone. Figure 2a,c,e demonstrate the temporal stability of the MF measurements of heterogeneous smartphones at a specific location. The MF reading of the iPhone Xs Max and Huawei P9 is quite stable (at least, during a short observation time period), while the MF measurements of the Bluebird are corrupted by outliers and strongly biased compared to the other two groups. From Figure 2b,d, we can see that the MF magnitude follows approximately a normal distribution. However, Figure 2f shows that Bluebird's MF measurements do not follow a normal distribution due to the effect of outliers. Table 3 summarizes the mean values, standard deviations, kurtosis, and skewness of MF intensity with heterogeneous smartphones. From the column of standard deviation, the standard deviation of the iPhone Xs Max is relatively low. Huawei's standard deviation is moderate, while Bluebird's standard deviation is the largest and the measurement uncertainty is the highest. Usually, the smaller the standard deviation of the smartphone, the smaller the fluctuation of the MF signal, the higher the certainty of MF measurement, and the better the positioning performance.  From the column of mean values, the MF intensity of the iPhone and Huawei are at the same level, while Bluebird's measurements are biased, well outside of the geomagnetic range of 23 µT to 62 µT [87]. The magnetometer calibration algorithm based on ellipsoidal fitting can correct the measurement distortions. The iPhone's kurtosis and skewness show a right-skewed normal distribution. At the same time, the Bluebird's measurements have many outliers, resulting in much larger kurtosis and skewness than those of the iPhone and Huawei. Based on the above analysis, we found that different smartphone manufacturers have different embedded magnetometer models, resulting in different MF measurements. Moreover, differences in processor performance make it difficult to achieve consistent sampling frequencies across heterogeneous smartphones.

Trajectory Test with Heterogeneous Smartphone
From Section 4.1, we have already confirmed that MF does not change over a short time period. In this section, we study the spatial distribution variability and temporal stability of heterogeneous smartphones' MF measurement. Users walked along the same path with heterogeneous smartphones to collect data at a sampling frequency of 100 Hz.
The experiment took place on the third floor of Polytech Galilee (Orléans, France), and the tested heterogeneous smartphones included the iPhone Xs Max, Samsung S9, Redmi Note 10 Pro, and Huawei P9.
As shown in Figure 3, the trajectories of the heterogeneous smartphones tested at different dates largely overlap, demonstrating that the indoor MF is stable over time without significant changes to the indoor infrastructure. The magnetic fingerprint, including local indoor disturbances, is stable over time without changes in indoor infrastructure. Previous works [11,26,27,30,88,89] have preliminarily explored these properties of MFs. Figure 4a shows that the heterogeneous smartphones have similar MF measurement trajectories under the same path.
Disturbances caused by building materials and electrical appliances lead to certain anomalies in the indoor MF. The pattern of disturbances varies from place to place, making the indoor MF spatially unique. Figure 4b shows that the smartphone has different MF measurements under different paths, demonstrating the MF's spatial uniqueness.

Rotation Test
Magnetometers are often fused with inertial sensors for pose estimation. Accurate MF measurements are essential for determining the user's heading and orientation. The construction of an MF map would be a tedious task if the MF measurement was dependent on orientation. MF measurements in various orientations at a specific point have been investigated.
A smartphone was placed on a rotatable platform, as shown in Figure 5; the smartphone frame was aligned with the platform frame, and the platform was rotated around the z axis of the smartphone. The MF database was collected at a sampling frequency of 100 Hz for 25 s.   MF positioning is based on the stability and uniqueness of the MF signature. In the positioning phase, smartphone measurement should match the MF database. The location with the shortest distance has the highest probability. However, as seen in Figure 6a, the x, y component and magnitude of MF also change periodically when the smartphone rotates periodically; only the z components remain relatively stable. Instead of using MF magnitude as a signature, it is better to use the z component as a fingerprint. The x and y axis of the MF can represent the variation in the magnetic direction. Figure 6b shows that the magnetic orientation varies between −180 • and 180 • , where the magnetic direction is calculated as follows: The ideal magnetic direction should be a standard sine curve, but the curve shown in Figure 6b is clearly not a sine curve and does not accurately represent the magnetic direction.  Figure 7a shows the MF measurements on the x, y, and z axis, where the MF measurements are approximately circular, illustrating that the soft iron effect can be ignored. Figure 7b shows the projection of the MF measurement on the xy coordinate; the actual center of the circle is at (4.65, 4.01) instead of at the ideal origin (0, 0), which indicates a hard iron effect of the MF measurement. Therefore, calibration of the smartphone is necessary. Figure 7c shows the projection of the MF measurement in the xz coordinate. The results show that the magnetic field does not change on the z axis, and the offset originates from the x and y axis.

Static Tests with Magnetometer
The previous analysis used a commercial smartphone with already pre-processed MF measurements by the manufacturer. An MF acquisition device, shown in Figure 8, was designed with the Arduino Pro Mini and 9-DoF LSM9DS1 [90] to study the unprocessed MF measurements; the software was developed using the open-source code available on the Arduino website [91]. Six designed devices (referred to as D1, D2, D3, D4, D5, and D6) were placed in a warehouse of width 45.69 m and height 49.5 m in the city of Tour, France. They continuously collected magnetic measurements in stationary mode for 9 days until the battery ran out. The robust locally weighted scatterplot smoothing (RLOWESS) method has been applied for outlier rejection [92]. Indeed, robust estimation methods generally involve the detection and mitigation of outliers, e.g., [31]. In our context, this pre-processing step is to avoid the large positioning bias that might be induced by such outliers. The robust weightings, multiplied with the neighborhood weight, are used for re-estimating a linear regression function: where w i is a neighborhood weight expressed as: x is the predictor, x i is the nearest neighbor of x as defined by the window slide, and˘q(x) is the distance of the qth farthest x i from x within the window slide. η i is the robust weight expressed as a bisquare function: where r i is the residual of the response value y and the predicted response valueŷ, and h is the median of the residuals h = median(|r i |) = median(|y i −ŷ i |). (13) In the following, we use the RLOWESS algorithm to smooth the MF measurements. Figure 9a shows that magnetic fingerprinting is not stable before filtering. There will be a sudden jitter without a calibration step.  A similar situation has been found for the Bluebird, where we believe that smartphone manufacturers have different standards for the calibration of magnetometers, resulting in different MF measurements. In this experiment, we used the RLOWESS method mentioned above to filter out outliers of MF measurement. The filtering result is shown in Figure 9c, and the histogram of filtered MF is given in Figure 9d. As we can see, the magnitude of MF intensities is different at different positions. The six quasi-normal distributions could be distinguished by visual inspection in this particular case. We can draw the conclusion from Table 4 that MF is stable for the considered period of time and subject to quasi-normal distribution. However, the conditioning of the sensors (or pre-filtering of their outputs) is necessary since all measurements are affected by outliers, which results in very high-level variance. The higher the variance, the worse the performance for positioning.

Calibration of Magnetic Field
Magnetometer calibration of a smartphone is actually the estimation of the calibration parameters A and b in Equation (8). In this paper, we use the batch magnetometer calibration method, where the smartphone is rotated along each direction to obtain magnetic field data, using the entire set of magnetic field measurements to estimate the unknown calibration parameters [93]. Supposing that magnetometer measurements are constant, and the local MF measurements are attitude-independent, to estimate the magnetometer error term, we can construct a cost function from the difference between the magnetometer measurement model and the true MF measurements [94]. Here, we present a calibration test with a different smartphone, and the calibration algorithm uses the work in [95]. We calculate the soft iron A and hard iron b of the smartphone at a given point and a given date. We tested these transformations (i.e., A and b) over a period of time to see if periodic re-calibration is necessary. Moreover, we tested the same calibration parameters at different points to see if they depend on the ambient location or only on the considered smartphone. To accomplish these goals, three smartphones (iPhone Xs Max, Huawei P9, Bluebird) have been used to continuously collect MF data at 10 points from February to June 2020 in 2 buildings; point 1 to point 7 are in building 1; point 8 to point 10 are in building 2. Smartphones were rotated around X, Y, Z, respectively, for 120 s for the aim of calibration. Figure 10 shows the calibration results at P1 on 7 February 2022, where the MF measurements of these smartphones are found to be spherical. This means that their distortion matrix approximates the identity matrix and the bias is negligible. Meanwhile, there is a significant bias for Bluebird (shown in Figure 10c), which needs to be eliminated. We calculated calibration parameters using MF measurements of P1 from three smartphones on 7 February 2020. The obtained calibration parameters were applied to Equation (14) to obtain true MF measurements at different times.
The rotation matrix and bias obtained at point P1 on the first day were used to calibrate all other data to demonstrate that the rotation matrix and bias of the MF are independent of time and space and only relate to the internal parameters of the smartphone. Figure 11a,c,e show the original MF magnitude of the iPhone Xs Max, Huawei P9, and Bluebird. Figure 11b,d,f show the calibrated MF magnitude of the iPhone Xs Max, Huawei P9, and Bluebird, respectively.
The X axis represents the 10 points where the magnetic field was collected. When we connect the MF intensity of the 10 points, we find that the six datasets collected over five months overlap, proving the magnetic field's temporal stability. MF intensity is different for P1 to P10, indicating that the MF measurement has spatial discernibility. As shown in Figure 11c, Huawei's MF measurements from P1 to P7 on 14 February 2020 are abnormal (blue line), but the rest of the time, the MF measurements follow the same trend as the iPhone Xs Max. Figure 11e shows that the Bluebird's original MF measurements do not overlap. The MF intensity varies between 80 and 110 µTesla, much greater than the iPhone Xs Max and Huawei P9. However, the calibrated MF intensity (shown in Figure 11f) is essentially the same as the MF intensity of the iPhone Xs Max and Huawei P9, suggesting that magnetometer calibration can solve the problem of smartphone heterogeneity. Figure 12a compares the MF intensity of the three smartphones from February to June. The MF intensities of the iPhone and Huawei are stable and overlap. Assuming that the iPhone is used to construct an MF map, Huawei can also use this MF map for positioning. However, the MF intensity of Bluebird is significantly different from the other two devices. The difference in the MF measurements of the heterogeneous smartphone is a significant challenge for MF positioning.  Figure 12b compares the calibrated magnitude of the P2 and P10 from February 2020 to June 2020. The calibrated MF intensity varies within a relatively stable range over five months, indicating that the calibration transformation is "stable" over time and over space. Heterogeneous smartphones have similar MF measurements at the same points. One can conclude that the MF calibration parameters are determined by the characteristics of the smartphone, and not by the environment. In addition, magnetometer calibration can solve the problem of heterogeneous equipment for MF.
Based on the above analysis, the original and calibrated magnitude of MF at each point remains stable over five months, while the surrounding environment remains unchanged. Different points have different mean values of MF intensity, which is an advantage for magnetic fingerprinting positioning. For the Huawei P9 and iPhone Xs, they have already been initially calibrated by the smartphone manufacturer. The iPhone Xs Max has the slightest standard deviation in MF intensity of the three smartphones. On 14 February 2020, the Huawei P9 had anomalies at P1, P3, P4, P5, P6, and P7. The standard deviation of these points is so significant that calibrating these values using the rotation matrix and bias from P1 on the first day would have resulted in substantial errors. The original magnitude of the Bluebird is not at the same level as the iPhone Xs Max and Huawei P9. However, the calibrated magnitude is at the same level for all three smartphones.

Classification Test with Calibration
The rapid development of artificial intelligence has attracted the attention of researchers who are applying machine learning methods to indoor positioning technology to address the limitations of traditional positioning techniques. The most important advantage of the machine learning approach is its ability to learn helpful information from input data with known or unknown statistics [61].
Positioning methods often need to consider positioning accuracy and computational complexity. Obtaining high-dimensional data through feature engineering can improve accuracy, but it also brings higher computational complexity. Dimensionality reduction techniques such as principal component analysis (PCA) [96] and singular value decomposition (SVD) [97] can transform high-dimensional features into low-dimensional features, significantly reducing the storage space and computational complexity of magnetic fingerprint-based positioning.
The architecture of a magnetic-based positioning system is shown in Figure 13. The system consists of two phases: online and offline [24]. First, raw magnetic data are collected at a reference location using a smartphone. Then, during the data pre-processing step, lowpass filters, smoothing filters, and calibration algorithms are applied to remove noise and bias from the smartphone's MF measurements. Thirdly, the pre-processed data construct a fingerprinting database corresponding to each location. The fingerprinting database is trained using machine learning methods (e.g., kNN, support vector machines, decision trees, naive Bayes, discriminant analysis) to obtain predictive models. Finally, a prediction model is used to predict the test data's position. We will focus on fuzzy kNN, support vector machines, decision trees, naive Bayes, and discriminant analysis in the following.
This experiment used three different smartphone models (iPhone Xs Max, Huawei P9, Bluebird) to test the location discernibility of local magnetic fingerprinting. Among them, Bluebird is an industrial custom smartphone for location-based services.
The test area is a corridor in the 3rd floor of Polytech Galilée, University of Orléans (shown in Figure 14); zones 1, 2, and 3 each contain 10 sampling points. Firstly, the user stands for 5 s at each point, holding a smartphone to capture a magnetic fingerprint database of 30 points with 100 Hz sampling frequency. Next, the user stands for 1 s at each point to capture test data and calculates the average of these 100 samples; this process was repeated five times to obtain 5 test datasets. Finally, we obtained n = 15,000 samples of training data X training = {x 1 , x 2 . . . x n | x i } ∈ R n×3 , and k = 150 samples of test data  Figure 14. Building of Polytech Orléans-Galilée, Univ. of Orléans with test zone 1, 2 and 3.
In the experiments, the test and training sets were collected in the same direction (along the corridor direction). The sampling interval between two successive points is set to 1.5 m. The height of a smartphone is set at 1.05 m distance from the ground.

Data Pre-Processing
In Section 5, we have already discussed the significance of MF calibration. Hence, in this experiment, the raw MF signal is pre-processed before classification tests. More precisely, the MF measurements are calibrated according to Equation (14), where the rotation matrix R nb comes from the TRIAD algorithm mentioned in [98]. MF measurement on the smartphone's frame is transformed into the horizontal (denoted as m h ) and vertical (denoted as m v ) components [27]. After this transformation, the horizontal and vertical components are "ideally" independent of the user's direction. Thus, the features of the training and test data can be expressed as: The RLOWESS smoothing filter mentioned in Section 4.4 is also used to eliminate anomalies in the smartphone's MF measurements.

Machine Learning Methods Used for Classification
Magnetic field positioning can be seen as a classification problem. Training data with labels are used to train the classifier in the training phase. Afterward, the new data are fed into the classifier for classification. The machine learning methods used for the tests will be briefly described here.
Fuzzy k-nearest neighbor: The fuzzy k-nearest neighbor algorithm [99] is a wellknown algorithm for classification. The theory of fuzzy sets was introduced into the k-nearest neighbor technique to develop a fuzzy version of this algorithm called fuzzy k-nearest neighbor. Not only does the fuzzy algorithm have the advantage of a lower error rate, but the resulting membership also provides a confidence level in the classification. Fuzzy k-nearest neighbor was shown to perform well compared to other more complex classification algorithms. The principle of the algorithm is to assign membership as a function of the Euclidean distance vector from the basic k-nearest neighbor algorithm and memberships in the possible classes.
Consider m feature samples X = {x 1 , x 2 . . . x n | x i ∈ R m } collected from n points in the test area (namely N labeled class). The second magnetic test set contains m feature samples y = y 1 , y 2 . . . y k | y j ∈ R m from l points, and we compute the metric where j = 1, 2 . . . , K, with K being the number of nearest neighbors; i = 1, 2 . . . , n, with n being the number of labeled classes. µ i (y) denotes the specified membership of vector y, and µ ij represents the membership of class i of the j-th vector for the labeled sample set. The fuzzy parameter m is used to determine the weights of the distances; here, we set m = 2. Decision tree: A decision tree is a non-parametric supervised learning technique consisting of multiple decision rules, all of which are derived from data features. In a decision tree, we call the whole sample the root node, and the process of dividing a node into two or more sub-nodes is called splitting. When a sub-node splits into more sub-nodes, it is called a decision node. Nodes that do not split are called leaves. The process of deleting the sub-nodes of a decision node is called pruning. The decision tree algorithm splits the training set (root node) into subsets, recursively splitting until no pure sub-nodes (leaf nodes) are obtained. The decision tree algorithm requires optimal attributes and thresholds that maximize the splitting criteria (e.g., CART Tree), and the resulting set of splits is optimal. Commonly used decision tree models such as the CART algorithm use Gini's impurity index, the ID3 algorithm uses Information Gain, and the C4.5 algorithm uses the Gain Ratio [59].
Naive Bayes: The naive Bayes classifier is based on Bayes' theorem. Suppose that m feature samples X = {x 1 , x 2 . . . x n | x i ∈ R m } belong to k class y = {y 1 , y 2 . . . y k }. According to Bayes' rule, P(y i | x) can be expressed as where P(y i ) and P(x) are known; to estimate the location, we need to find the corresponding location y i that maximizes P(x | y i ). Since the magnetic values obey a Gaussian distribution, i.e., P(x | y i ) ∼ N (µ, σ 2 ), µ and σ are derived from the training set [58]. Discriminant analysis: Discriminant analysis methods are well known for learning discriminative feature transformations and can be easily extended to multiple-class cases [100]. Suppose that we have m feature samples X = {x 1 , x 2 . . . x n | x i ∈ R m } belonging to k class y = {y 1 , y 2 . . . y k }. The within-class scatter matrix is given as: where µ i = 1 l i ∑ x∈y i x and l i is the number of samples in y i . The between-class scatter matrix equation is defined asΣ where l i is the number of training samples for each class, µ i is the mean for each class, and µ is the total mean vector given by µ = 1 l ∑ n i=1 l i µ i . The Fisher criterion suggests that the linear transformation w maximizes the ratio of the determinant of the between-class scatter matrix of the projected samples to the within-class scatter matrix of the projected samples [60] The transformation w can be obtained by solving the generalized eigenvalue problem [100]: Discriminant analysis has also its limitations; it assumes a unimodal Gaussian likelihood, and for non-Gaussian distributions, discriminant analysis predictions will not preserve any complex structure of the data. It fails when the discriminant information is not in the mean but in the variance of the data. Support vector machine: Support vector machine classifies data by finding the best hyperplane, which is the hyperplane with the maximum distance between two classes. Consider m feature samples X = {x 1 , x 2 . . . x n | x i ∈ R m } belonging to k labels y = {y 1 , y 2 . . . y k }. The i-th SVM is trained using all examples with positive labels in the i-th class and all other examples with negative labels, and the i-th SVM is formulated as follows: where the training data x i are mapped to a higher-dimensional space by a function f , w ∈ R m is a vector representing the direction of the separated hyperplane, b ∈ R is a constant representing the position of the hyperplane, C is the penalty parameter that defines the trade-off between large separation regions and misclassification errors, and ξ i j is a slack variable that allows some samples to be on the wrong side of the separation hyperplane [101][102][103].
According to Equation (22), we can obtain the decision functions where x belongs to the class with the largest value of the decision function.

Classification Result
The test zones are shown as three rectangles in Figure 14, with 10 test points in zones 1, 2, and 3, respectively. The green area is the elevator, which is a source of magnetic interference. Figure 15 shows the "calibrated" MF intensity at 10 points in zone two as an illustrative example to visually analyze the MF magnitude fingerprints in this zone. The Huawei device has a more significant variance in the MF intensity than the other two smartphones, with more overlap between the signals. Bluebird's database shows that there is an overlap between P12, P15 and P20, P18, and P19. The iPhone has a slight overlap between P12 and P13. First, we test the training and test sets from the same smartphone separately, and the results are shown in Table 5. The positioning accuracies of the iPhone Xs Max and Bluebird are relatively similar (close to 80 or above), basically meeting the needs of essential indoor positioning. In contrast, the positioning accuracy of the Huawei P9 is significantly lower than the other two smartphones. Figure 16 shows the confusion matrix for the three smartphones using the KNN method, blue indicates correctly classified points, other colors indicate incorrectly classified points.Huawei P9 performs better in zone 2 (landmark 11 to landmark 20) and does not have high positioning accuracy in zones 1 and 3. The elevator in the green area of Figure 14 is a source of magnetic field interference, making this area even more special. The results from Huawei P9 show that the interference source improves the positioning performance (i.e., it enhances the differences between the MF features). The variances of the MF measurements for the iPhone Xs Max, Bluebird, and Huawei P9 are 0.04 µT, 0.12 µT, and 0.21 µT, respectively. As the intensity of the magnetic field varies smoothly between 23 µTesla and 62 µTesla [87], the larger the variance, the more likely it is to overlap with other signals within a limited variation interval, which degrades the positioning performance. Due to the significant variance of the MF measurement, Huawei's positioning accuracy is lower than the other two smartphones.  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30 True Class  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30 True Class  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30 True Class  Next, we use the iPhone Xs Max for the training set to obtain the prediction model and test the other two smartphones separately. Table 6 illustrates the positioning accuracy. We can see that the positioning accuracy decreases when the magnetic fingerprinting database and the test data are inconsistent compared to Table 5. We already saw earlier that the Bluebird's MF measurement is significantly different from the other two smartphones. Nonetheless, using the calibrated Bluebird's MF measurement, we can also achieve accuracy of approximately 50%, which means that we have the opportunity to use the iPhone to create a magnetic field fingerprint database that other smartphones can use for positioning.
We can also see that KNN, discriminant analysis, and SVM have better positioning accuracy than decision tree and naive Bayes in this experiment.

Conclusions
With the widespread use of smartphones, ubiquitous magnetic fields are attracting researchers' interest. The use of smartphones to measure magnetic fields for indoor positioning has significant advantages: infrastructure-free, temporal stability, and spatial uniqueness.
However, there are also significant challenges highlighted by our study: • Firstly, the use of MF data requires the processing of device heterogeneity. The magnetometers with different specifications used by smartphone manufacturers result in different MF measurements. Hence, MF fingerprinting would require the use of smartphones/magnetometers which have similar characteristics to ensure the efficiency of such a positioning approach. • Data pre-processing is necessary in order to exploit the MF data. This includes filtering out the outliers that affect the magnetometer measurements (in this work, we propose the RLOWESS algorithm to smooth the MF measurements). It also includes the calibration of the magnetometer, which is necessary to eliminate soft and hard iron influences.

•
The magnetic signatures of heterogeneous smartphones on the same path have the same pattern but do not overlap. As the X and Y axes of the magnetic field are directiondependent, the MF intensity of the smartphone fluctuates as it rotates around the Z axis, which is challenging for magnetic field map construction. • Calibration tests were carried out with different smartphones in specific locations at given dates. It was found that the calibration parameters of the smartphones depend only on its specifications and not on the environment. There is no need to re-estimate the calibration transform periodically or for different locations. • The MF collected by one smartphone is calibrated as a fingerprint database, and other smartphones can use this MF fingerprint database for positioning. This method can somewhat solve the MF positioning problem of heterogeneous devices. However, we can still see that the positioning accuracy of heterogeneous devices is significantly lower than that of homogeneous devices. • Interference sources may enhance the specificity of local MF fingerprints (e.g., proximity to fridges, lifts, metal doors). In the above experiment, the Huawei P9's positioning accuracy was significantly higher in zone 2 than in the other two zones.